package com.gopay.common.cps.dao.order.impl;

import com.gopay.common.base.dao.impl.BaseReadDAOImpl;
import com.gopay.common.cps.dao.order.CpsGeneralFundAgreementQueryDAO;
import com.gopay.common.domain.fund.FundGopayAgreementEntity;
import org.springframework.stereotype.Repository;

import java.io.Serializable;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 基金支付类订单明细表DAO
 * 
 */

@Repository(value="cpsGeneralFundAgreementQueryDAO")
public class CpsGeneralFundAgreementQueryDAOImpl extends BaseReadDAOImpl<FundGopayAgreementEntity, Serializable> implements
        CpsGeneralFundAgreementQueryDAO {

    /**
     * 查询
     * @param start
     * @param end
     * @param type
     * @return
     * @throws SQLException
     */
    @Override
    public List<FundGopayAgreementEntity> findorder(String start, String end, String[] type) throws SQLException {

        StringBuilder sb = new StringBuilder();

        if(start!=null && !"".equals(start) && end!=null && !"".equals(end) && type.length>0) {

            StringBuilder typeS = new StringBuilder();
            for(int i = 0; i < type.length; i++) {
                if(type.length-1==i) {
                    typeS.append("'"+type[i]+"'");
                }else {
                    typeS.append("'"+type[i]+"'"+",");
                }
            }
            sb.append("  from  FundGopayAgreementEntity t where");
            sb.append(" t.LAST_UPD_TS < to_timestamp(:dateEnd, 'yyyymmddHH24miss') ");
            sb.append("  and t.LAST_UPD_TS >= to_timestamp(:dateBegin, 'yyyymmddHH24miss') ");
            sb.append("  and t.STATUS = '1'");
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("dateBegin",start+"");
            map.put("dateEnd",end+"");

            List<FundGopayAgreementEntity> byHql = findByHql(sb.toString(),map);
            return byHql;

        }
        return null;
    }



}
